<template>
	<view class="canclelist">
		<view class="content" v-for="(item,index) in orderList" :key="index">
			<view class="shops">
				<image class="shop_img" :src="item.goods_cover"></image>
				<view class="shops_right">
					<view class="name">{{item.goods_name}}</view>
					<view class="infos">
						<view class="price_msg">
							拼购价:
							<text class="price">￥{{item.buy_price}}</text>
						</view>
						<text class="group_type"
							v-if="item.type == '2'">{{item.partake_number}}/{{item.custom_number}}</text>
						<text class="group_type" v-if="item.type == '3'">今日拼中为止</text>
					</view>
					<view class="create_time">
						<text>{{item.create_date}}</text>
						<button type="default" size="mini" class="apply_btn" @click="openPop(item)">取消</button>
					</view>
				</view>
			</view>
		</view>

		<view v-show="isLoadMore && orderList.length >0">
			<uni-load-more :status="loadStatus"></uni-load-more>
		</view>

		<view class="nodata" v-if="orderList.length == 0">
			<image class="empty_img" :src="IMGLink+'/my/empty.png'" mode="widthFix"></image>
			<view>没有你想要的内容</view>
		</view>
	</view>
</template>

<script>
	import {
		grouplist
	} from "@/api/my/my.js";
	export default {
		data() {
			return {
				IMGLink: this.IMGLink,
				orderList: [],
				page: 1, //页码
				size: '10',
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				refresh: false, // 下拉刷新标示
			}
		},
		onLoad() {
			this.getDataList();
		},
		methods: {
			getDataList() {
				uni.showLoading({
					title: '加载中'
				});
				grouplist('canCancelGroupBuyList', {
					page: this.page,
					page_size: this.size,
					status: this.status,
				}).then(res => {
					let datas = res.data.list;

					this.orderList = this.page == 1 ? datas : this.orderList.concat(datas);
					if (datas.length < this.size) { //小于size数，停止请求
						this.isLoadMore = true;
						this.loadStatus = 'nomore';
					} else {
						this.isLoadMore = false;
					}
					uni.hideLoading();

					if (this.refresh) {
						uni.stopPullDownRefresh();
						this.refresh = false;
					}
				}).catch(error => {
					uni.hideLoading();
					this.isLoadMore = false;
				})
			},
			onPullDownRefresh() {
				this.page = 1;
				this.getDataList();
				this.refresh = true;
			},
			onReachBottom() {
				if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
					this.isLoadMore = true;
					this.page++;
					this.getDataList();
				}
			},
			openPop(item) {
				wx.showModal({
					title: '提示',
					content: '确认是否取消连续拼购？',
					cancelColor: '#616161',
					confirmColor: '#FF2A36',
					success: (res)=> {
						if (res.confirm) {
							this.doCancel(item.id);
						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
			},
			doCancel(id) {
				uni.showLoading({
					title: '取消中'
				});
				grouplist('cancelGroupBuy', {
					id: id
				}).then(res => {
					if (res.code == 200) {
						uni.hideLoading();
						this.isToast(res.msg);
						this.page = 1;
						this.getDataList();
					}
				}).catch(error => {
					uni.hideLoading();
				})
			},
			isToast(text) {
				uni.showToast({
					title: text,
					icon: 'none',
				});
			},
		}
	}
</script>
<style>
	page {
		background-color: #EFF0F1;
	}
</style>
<style lang="scss" scoped>
	@import "../my.scss";

	.content {
		@include cards;
		background-color: #FFFFFF;
		padding: 20rpx;
		margin: 30rpx 3% 20rpx;
		font-size: 24rpx;
		color: #0A0C0D;

		.shops {
			@include flexLayout(center, space-between);
			padding: 14rpx 0 30rpx;

			.shop_img {
				width: 138rpx;
				height: 166rpx;
				border-radius: 12rpx;
			}

			&_right {
				width: 75%;

				.name {
					@include exceedFlow(2);
				}

				.infos {
					@include flexLayout(center, flex-start);
					color: #0B0B0D;
					font-size: 28rpx;
					margin: 10rpx 0;

					.price {
						color: #F54642;
					}

					.price_msg,
					.group_type {
						color: #4C4C4C;
						margin-right: 12rpx;
					}
				}

				.create_time {
					@include flexLayout(center, space-between);
					color: #868686;

					.apply_btn {
						width: 134rpx;
						height: 50rpx;
						line-height: 50rpx;
						background: #F54642;
						color: #FFFFFF;
						border-radius: 44rpx;
						margin: 0;
						padding: 0;
					}
				}
			}
		}
	}

	.nodata {
		text-align: center;
		color: #7D7D7D;
		font-size: 24rpx;
		margin-top: 50%;

		.empty_img {
			width: 468rpx;
		}
	}
</style>
